from automationclient import AutomationClient
import logging
import multiprocessing
import msvcrt
import time
import sys
import locale

def GetExitsFlag():
    if msvcrt.kbhit() and msvcrt.getch() == 'q':
        return True
    return False

def main():
    try:
        multiprocessing.freeze_support()
        lang, code = locale.getdefaultlocale()
        reload(sys)
        sys.setdefaultencoding(code)
        client  = AutomationClient()
        if not client.Init():
            logging.warn('automation fail')
            return
        
        while not GetExitsFlag() and not (client.IsQuit()):
            client.Loop()
            time.sleep(0.2)
        
        client.Uninit()
        
        logging.info('client exit')
    except Exception as e:
        logging.exception(e)
        
        

if __name__ == '__main__':
    main()